package com.pinfly.common.config;

import java.util.Collection;

import org.apache.log4j.Logger;

public class PfyPropertiesFactory
{
    private static final Logger logger = Logger.getLogger (PfyPropertiesFactory.class);

    /** instance of current properties implementation */
    private static IPfyProperties s_cfgProperties;

    static
    {
        s_cfgProperties = new PfyPropertiesImpl ();
    }

    /**
     * Returns the ICfgProperties implementation
     * 
     * @return ICfgProperties
     */
    public static IPfyProperties getInstance ()
    {
        return s_cfgProperties;
    }

    /**
     * Returns the CxxProperties for the specified group.
     * 
     * @param groupName
     * @return A CxxProperties instance for the group.
     * @throws ConfigException If there were issues retrieving the properties
     * @throws ResourceNotFoundException If the specified resource does not
     *             exist or is is not assigned to an hln
     * @throws IllegalArgumentException if groupName is null or empty
     */
    public static PfyProperties getProperties (String groupName) throws ConfigException
    {
        return s_cfgProperties.getProperties (groupName);
    }

    /**
     * Returns the CxxProperties for the specified group, using the filepath as
     * the directory to retrieve the properties. The filepath is only used for
     * file-based implementations. In the config server implementation the
     * filepath is ignored.
     * 
     * @param filePath
     * @param groupName
     * @return A CxxProperties instance for the group.
     * @throws ConfigException If there were issues retrieving the properties
     * @throws ResourceNotFoundException If the specified resource does not
     *             exist or is is not assigned to an hln
     * @throws IllegalArgumentException if groupName is null or empty
     * @throws IllegalArgumentException if filePath is null or empty
     */
    public static PfyProperties getProperties (String filePath, String groupName) throws ConfigException
    {
        return s_cfgProperties.getProperties (filePath, groupName);
    }

    /**
     * Returns a Collection of CxxProperties from the specified list of groups.
     * 
     * @param groupNames
     * @return A Collection of CxxProperties objects.
     * @throws ConfigException If there were issues retrieving the properties
     * @throws ResourceNotFoundException If the specified resource does not
     *             exist or is is not assigned to an hln
     * @throws IllegalArgumentException if groupNames is null or empty
     */
    public static Collection <PfyProperties> getProperties (Collection <String> groupNames) throws ConfigException
    {
        return s_cfgProperties.getProperties (groupNames);
    }

    /**
     * Returns a Collection of CxxProperties from the specified list of groups,
     * using the filepath as the directory to retrieve the properties. The
     * filepath is only used for file-based implementations. In the config
     * server implementation the filepath is ignored.
     * 
     * @param filePath
     * @param groupNames
     * @return A Collection of CxxProperties objects.
     * @throws ConfigException If there were issues retrieving the properties
     * @throws ResourceNotFoundException If the specified resource does not
     *             exist or is is not assigned to an hln
     * @throws IllegalArgumentException if groupNames is null or empty
     * @throws IllegalArgumentException if filePath is null or empty
     */
    public static Collection <PfyProperties> getProperties (String filePath, Collection <String> groupNames)
                                                                                                            throws ConfigException
    {
        return s_cfgProperties.getProperties (filePath, groupNames);
    }

    /**
     * Returns the properties from the specified list of groups.
     * 
     * @param groupNames
     * @return A GroupMap object.
     * @throws ConfigException If there were issues retrieving the properties
     * @throws ResourceNotFoundException If the specified resource does not
     *             exist or is is not assigned to an hln
     * @throws IllegalArgumentException if groupNames is null or empty
     */
    public static GroupMap getPropertiesMap (Collection <String> groupNames) throws ConfigException
    {
        return s_cfgProperties.getPropertiesMap (groupNames);
    }

    /**
     * Returns the properties from the specified list of groups, using the
     * filepath as the directory to retrieve the properties. The filepath is
     * only used for file-based implementations. In the config server
     * implementation the filepath is ignored.
     * 
     * @param filePath
     * @param groupNames
     * @return A GroupMap object.
     * @throws ConfigException If there were issues retrieving the properties
     * @throws ResourceNotFoundException If the specified resource does not
     *             exist or is is not assigned to an hln
     * @throws IllegalArgumentException if groupNames is null or empty
     * @throws IllegalArgumentException if filePath is null or empty
     */
    public static GroupMap getPropertiesMap (String filePath, Collection <String> groupNames) throws ConfigException
    {
        return s_cfgProperties.getPropertiesMap (filePath, groupNames);
    }

}
